{{!
  Copyright IBM Corp. 2016, 2025
  SPDX-License-Identifier: BUSL-1.1
}}
{{#let (engines-display-data @model.secretsEngine.type) as |engineDisplayData|}}
  <Page::Header
    @title="{{@model.secretsEngine.id}} configuration"
    @description={{engineDisplayData.displayName}}
    @icon={{engineDisplayData.glyph}}
    @subtitle={{engineDisplayData.typeDisplay}}
  >
    <:breadcrumbs>
      <Page::Breadcrumbs @breadcrumbs={{@breadcrumbs}} />
    </:breadcrumbs>
    <:tabs>
      <SecretEngine::ConfigureTabs @config={{@model.config}} @secretsEngine={{@model.secretsEngine}} />
    </:tabs>
  </Page::Header>
{{/let}}

{{#if this.saveGeneralSettings.isRunning}}
  {{! TODO: Fix loading state styles }}
  <Hds::Layout::Flex @gap="24" @direction="column" @justify="center" @align="center">
    <div class="one-fourth-width">
      <Hds::Icon @name="loading-static" @size="24" @stretched={{true}} />
    </div>
    <Hds::Text::Display @tag="h2">Saving configuration...</Hds::Text::Display>
  </Hds::Layout::Flex>
{{else}}
  <form
    method="POST"
    {{on "submit" (perform this.saveGeneralSettings)}}
    aria-label="general settings form"
    id="general-settings-form"
  >
    <Hds::Text::Body class="has-top-bottom-margin-xxs">
      Mount parameters that you can tune to fit required engine behavior.
    </Hds::Text::Body>

    <MessageError @errorMessage={{this.errorMessage}} @errors={{this.errors}} />

    <Hds::Layout::Grid @columnMinWidth="32%" @gap="32" as |LG|>
      <LG.Item @colspan={{1}}>
        <SecretEngine::Card::Version @model={{@model}} class="is-fullwidth" />
        <SecretEngine::Card::Metadata @model={{@model}} class="is-fullwidth" />
      </LG.Item>
      <LG.Item @colspan={{1}}>
        <SecretEngine::Card::SecretsDuration
          @model={{@model}}
          @defaultLeaseUnit={{this.defaultLeaseUnit}}
          @maxLeaseUnit={{this.maxLeaseUnit}}
          class="is-fullwidth"
        />
        <SecretEngine::Card::Security @model={{@model}} class="is-fullwidth" />
      </LG.Item>
    </Hds::Layout::Grid>
    <div class="field is-grouped has-top-bottom-margin">
      <Hds::ButtonSet>
        <Hds::Button @text="Save changes" type="submit" disabled={{this.saveGeneralSettings.isRunning}} data-test-submit />
        <Hds::Button @text="Discard" @color="secondary" {{on "click" this.discardChanges}} data-test-cancel />
      </Hds::ButtonSet>
    </div>
  </form>
{{/if}}

<UnsavedChangesModal
  @onSave={{this.saveGeneralSettings}}
  @onDiscard={{this.discardChanges}}
  @changedFields={{this.modalChangedFields}}
/>